package com.atwisdom.star.core.bsl.business.Impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.atwisdom.star.common.util.DateUtils;
import com.atwisdom.star.core.bsl.business.StatisticBslService;
import com.atwisdom.star.core.dao.pojo.modelClass.hier.HierInstance;
import com.atwisdom.star.core.dsl.modelClass.hier.Impl.HierInstanceDslServiceImpl;
import com.atwisdom.star.core.dsl.modelClass.logic.Impl.LogicInstanceDslServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.stream.Collectors;

@Service
public class StatisticBslServiceImpl implements StatisticBslService {
    private LogicInstanceDslServiceImpl logicInstanceDslService;

    private HierInstanceDslServiceImpl hierInstanceDslService;

    @Autowired
    public void setHierInstanceDslService(HierInstanceDslServiceImpl hierInstanceDslService) {
        this.hierInstanceDslService = hierInstanceDslService;
    }

    @Autowired
    public void setLogicInstanceDslService(LogicInstanceDslServiceImpl logicInstanceDslService) {
        this.logicInstanceDslService = logicInstanceDslService;
    }

    //建立listMap ,统计原子表
    //最小统计单，
    //流程：1、批次号，工单->一组设备->报工主记录（工单号、报工单号）->报工记录（开始--结束时间）
    //字段：主键 报工记录号（开始时间，结束时间）、机台号、数量、单位、批次号
    //说明：报工需要明确机台
    private final List<Map<String, Object>> atom = new ArrayList<>();

    //建立productMap ,统计产品表
    //主键 报工记录号（开始时间，结束时间）、机台号、数量、单位、报废数量、不良数量、良品数量、批次号
    private final List<Map<String, Object>> product = new ArrayList<>();

    //按批次统计表
    private final List<Map<String, Object>> batch = new ArrayList<>();

    //按批次统计
    private void statisticBatch(String batchNumber) {
        //通过批次获取机台数
        String workUnit = this.getWorkUnits(batchNumber);
        String reportRecordNumber = getReportNumber(batchNumber, workUnit);
        if (StringUtils.isBlank(reportRecordNumber)) {
            System.out.println("批次号：" + batchNumber + "没有报工记录");
            return;
        }

        this.statisticReport(reportRecordNumber); //如果不是连续统计、该方法应该改为从数据库中获取

        //1、主键（批次号、设备号、品番、背番）、数量、单位、报废数量、不良数量、良品数量、开始时间、结束时间，设备有效时间、人员有效时间、类型（产品）
        //批次号、设备号、品番、背番、数量、单位、报废数量、不良数量、良品数量 来自产品表的聚合统计
        //设备有效时间、人员有效时间 来自天原子表的聚合统计
        //统计结果加入到batchMapList中
        List<Map<String, Object>> batchMapList = new ArrayList<>();
        //2、主键（批次号、设备号、品番）、数量、单位、类型（原材料）
        //通过this.atomMaterial(batchNumber);统计出来
        this.atomMaterial(batchNumber);
//        batchMapList.add(materialMap);

        //还有些可能需要考虑的，比如质量、模具相关的跟批次号有关，扩展 1、或增加一张表进行统计
    }

    /**
     *
     * @param reportRecordNumber
     */
    private void statisticReport(String reportRecordNumber) {
        List<JSONObject> reportRecords = getWorReportRecords(reportRecordNumber);
        for (JSONObject reportRecord : reportRecords) {
            this.atomPeople(reportRecord);
            this.atomEquip(reportRecord);
            this.atomProduct(reportRecord);
        }
    }

    /****************************获取人、机、料基础方法**********************************/

    /**
     * 领料数据获取
     * @param batchNumber
     * @return
     */
    private void atomMaterial(String batchNumber) {
        //获取领料数据
        List<JSONObject> materialRecords = getPickMaterialRecords(batchNumber);
        List<Map<String, Object>> materialMapList = new ArrayList<>();
        buildMaterialMap(batchNumber, materialRecords,0, materialMapList);
        //获取退料数据
        List<JSONObject> materialReturnRecords = getReturnMaterialRecords(batchNumber);
        buildMaterialMap(batchNumber, materialReturnRecords,1, materialMapList);
        //获取用料数据
        List<JSONObject> useMaterialRecords = getUseMaterialRecords(batchNumber);
        buildMaterialMap(batchNumber, useMaterialRecords,2, materialMapList);
        //对物料数据进行汇总
        Map<List<Object>, Map<String, Double>> materialInfoList = materialMapList.stream()
                .collect(Collectors.groupingBy(map -> Arrays.asList(map.get("batchNumber"), map.get("uniqueCode"), map.get("material_id"), map.get("material_pcode"), map.get("material_bcode"), map.get("material_unit")),
                        Collectors.collectingAndThen(Collectors.toList(), list -> {
                            Double quantity = list.stream().mapToDouble(m -> (int) m.get("quantity")).sum();
                            Double returnQuantity = list.stream().mapToDouble(m -> (int) m.get("returnQuantity")).sum();
                            Double useQuantity = list.stream().mapToDouble(m -> (int) m.get("useQuantity")).sum();
                            return new HashMap<String, Double>() {{
                                put("quantity", quantity);
                                put("returnQuantity", returnQuantity);
                                put("useQuantity", useQuantity);
                            }};
                        })));

        //整理数据并保存到用料表中
        materialInfoList.forEach((key, value) -> {
            Map<String, Object> materialMap = new HashMap<>();
            materialMap.put("batchNumber", key.get(0));
            materialMap.put("uniqueCode", key.get(1));
            materialMap.put("material_id", key.get(2));
            materialMap.put("material_pcode", key.get(3));
            materialMap.put("material_bcode", key.get(4));
            materialMap.put("quantity",value.get("quantity"));
            materialMap.put("returnQuantity",value.get("returnQuantity"));
            materialMap.put("useQuantity",value.get("useQuantity"));
            this.addMaterial(materialMap);
        });
    }

    /**
     * 物料领退数据获取
     * @param batchNumber     批次号
     * @param materialRecords 物料记录集
     * @param typeFlag        领退标识，0:领料，1: 退料, 2: 用料
     * @param materialMapList
     */
    private void buildMaterialMap(String batchNumber, List<JSONObject> materialRecords, int typeFlag, List<Map<String, Object>> materialMapList) {
        for (JSONObject materialRecord : materialRecords) {
            //计算领料数量
            Map<String, Object> materialMap = new HashMap<>();
            materialMap.put("batchNumber", batchNumber);
            materialMap.put("material_id", materialRecord.getLong("material_id"));
            materialMap.put("material_pcode", materialRecord.getString("material_pcode"));
            materialMap.put("material_bcode", materialRecord.getString("material_bcode"));
            materialMap.put("material_unit", materialRecord.getString("material_unit"));
            if (typeFlag == 0) {
                materialMap.put("quantity", materialRecord.getDouble("quantity"));
                materialMap.put("returnQuantity", 0.0);
                materialMap.put("useQuantity", 0.0);
            } else if(typeFlag == 1){
                materialMap.put("quantity", 0.0);
                materialMap.put("returnQuantity", materialRecord.getDouble("quantity"));
                materialMap.put("useQuantity", 0.0);
            }else {
                materialMap.put("quantity", 0.0);
                materialMap.put("returnQuantity", 0.0);
                materialMap.put("useQuantity", materialRecord.getDouble("quantity"));
            }
            materialMap.put("uniqueCode", materialRecord.getString("uniqueCode"));
            materialMapList.add(materialMap);
        }
    }

    /**
     * 报工人员信息原子统计
     * @param reportRecord 报工记录
     */
    private void atomPeople(JSONObject reportRecord) {
        String reportRecordNumber = reportRecord.getString("reportRecordNumber");
        Date startDate = reportRecord.getDate("workReportBeginTime");
        Date endDate = reportRecord.getDate("workReportEndTime");
        Double pauseDuration = reportRecord.getDouble("workReportStopDuration");
        if(pauseDuration==null){
            pauseDuration=0.0;
        }
        JSONArray operatorJsonArray = reportRecord.getJSONArray("operator");
        List<Long> operatorIds = JSONUtil.parseArray(operatorJsonArray).toList(Long.class);
        JSONArray operatorNameJsonArray = reportRecord.getJSONArray("operator_name");
        List<String> operatorNames = JSONUtil.parseArray(operatorNameJsonArray).toList(String.class);
        String batchNumber = reportRecord.getString("batchNumber");
        String durationUnit = "小时";
        Double during = DateUtils.getHoursBetween(startDate, endDate) - pauseDuration;
        //成品、单成品
        Double goodQuantity = reportRecord.getDouble("workReportNumber"); //合格品数量
        Double poorQuantity = reportRecord.getDouble("poorNumber"); //不良品
        Double scrapQuantity = reportRecord.getDouble("scrapNumber"); //报废品
        String unit = reportRecord.getString("material_unit"); //合格品数量
        for (int i = 0; i < operatorIds.size(); i++) {
            Long personId = operatorIds.get(i);
            String personName = operatorNames.get(i);
            Map<String,Object> map = formatAtomTable(batchNumber,
                    reportRecordNumber,
                    startDate,
                    endDate,
                    pauseDuration,
                    during,
                    durationUnit,
                    personId,
                    personName,
                    null,
                    null,
                    null,
                    goodQuantity,
                    poorQuantity,
                    scrapQuantity,
                    unit);
           this.addRecord(map);
        }
    }

    private void atomEquip(JSONObject reportRecord) {
        String reportRecordNumber = reportRecord.getString("reportRecordNumber");
        Date startDate = reportRecord.getDate("workReportBeginTime");
        Date endDate = reportRecord.getDate("workReportEndTime");
        Double pauseDuration = reportRecord.getDouble("workReportStopDuration");
        if(pauseDuration==null){
            pauseDuration=0.0;
        }
        JSONArray equipIdJsonArray = reportRecord.getJSONArray("equipIds");
        List<Long> equipIds = JSONUtil.parseArray(equipIdJsonArray).toList(Long.class);
        JSONArray equipCodeJsonArray = reportRecord.getJSONArray("equipCodes");
        List<String> equipCodes = JSONUtil.parseArray(equipCodeJsonArray).toList(String.class);
        JSONArray equipNameJsonArray = reportRecord.getJSONArray("equipNames");
        List<String> equipNames = JSONUtil.parseArray(equipNameJsonArray).toList(String.class);
        String batchNumber = reportRecord.getString("batchNumber");
        String durationUnit = "小时";
        Double during = DateUtils.getHoursBetween(startDate, endDate) - pauseDuration;
        //成品、单成品
        Double goodQuantity = reportRecord.getDouble("workReportNumber"); //合格品数量
        Double poorQuantity = reportRecord.getDouble("poorNumber"); //不良品
        Double scrapQuantity = reportRecord.getDouble("scrapNumber"); //报废品
        String unit = reportRecord.getString("material_unit"); //单位
        for (int i = 0; i < equipIds.size(); i++) {
            Long equipId = equipIds.get(i);
            String equipCode = equipCodes.get(i);
            String equipName = equipNames.get(i);
            Map<String,Object> map = formatAtomTable(batchNumber,
                    reportRecordNumber,
                    startDate,
                    endDate,
                    pauseDuration,
                    during,
                    durationUnit,
                    null,
                    null,
                    equipId,
                    equipCode,
                    equipName,
                    goodQuantity,
                    poorQuantity,
                    scrapQuantity,
                    unit);
            this.addRecord(map);
        }
    }

    /**
     * 封装产品原子统计表
     * @param reportRecord
     */
    private void atomProduct(JSONObject reportRecord) {
        Date startDate = reportRecord.getDate("workReportBeginTime");
        Date endDate = reportRecord.getDate("workReportEndTime");
        String batchNumber = reportRecord.getString("batchNumber");
        String reportRecordNumber = reportRecord.getString("reportRecordNumber");
        String material_pcode = reportRecord.getString("material_pcode");
        String material_bcode = reportRecord.getString("material_bcode");
        String material_unit = reportRecord.getString("material_unit");
        Double goodQuantity = reportRecord.getDouble("workReportNumber"); //合格品数量
        Double poorQuantity = reportRecord.getDouble("poorNumber"); //不良品
        Double scrapQuantity = reportRecord.getDouble("scrapNumber"); //报废品
        Double quantity = goodQuantity+poorQuantity+scrapQuantity;
        Map<String,Object> map = formatProductTable(batchNumber,
                reportRecordNumber,
                startDate,
                endDate,
                material_pcode,
                material_bcode,
                quantity,
                goodQuantity,
                poorQuantity,
                scrapQuantity,
                material_unit);
        this.addProduct(map);
    }

    /****************************格式化及验证字段**********************************/
    private Map<String, Object> formatProductTable(String batchNumber, String reportRecordNumber, Date startDate, Date endDate, String pCode,
                                                   String bCode, Double quantity, Double goodQuantity,
                                                   Double poorQuantity, Double scrapQuantity, String unit) {
        Map<String, Object> productMap = new HashMap<>();
        productMap.put("batchNumber", batchNumber);
        productMap.put("reportRecordNumber", reportRecordNumber);
        productMap.put("startDate", DateUtils.getDateFormat(startDate, "yyyy-MM-dd HH:mm:ss"));
        productMap.put("endDate", DateUtils.getDateFormat(endDate, "yyyy-MM-dd HH:mm:ss"));
        productMap.put("pCode", pCode);
        productMap.put("bCode", bCode);
        productMap.put("quantity", quantity);
        productMap.put("goodQuantity", goodQuantity);
        productMap.put("poorQuantity", poorQuantity);
        productMap.put("scrapQuantity", scrapQuantity);
        productMap.put("unit", unit);
        return productMap;
    }
    private Map<String, Object> formatAtomTable(String batchNumber, String reportRecordNumber, Date startDate, Date endDate, Double pauseDuration, Double during,
                                String durationUnit, Long personId, String personName, Long equipId, String equipNumber,
                                String equipName, Double goodQuantity, Double poorQuantity, Double scrapQuantity, String unit) {
        Map<String, Object> atomMap = new HashMap<>();
        atomMap.put("batchNumber", batchNumber);
        atomMap.put("reportRecordNumber", reportRecordNumber);
        atomMap.put("startDate", DateUtils.getDateFormat(startDate, "yyyy-MM-dd HH:mm:ss"));
        atomMap.put("endDate", DateUtils.getDateFormat(endDate, "yyyy-MM-dd HH:mm:ss"));
        atomMap.put("pauseDuration", pauseDuration);
        atomMap.put("during", during);
        atomMap.put("durationUnit", durationUnit);
        atomMap.put("personId", personId);
        atomMap.put("personName", personName);
        atomMap.put("equipId", equipId);
        atomMap.put("equipNumber", equipNumber);
        atomMap.put("equipName", equipName);
        atomMap.put("goodQuantity", goodQuantity);
        atomMap.put("poorQuantity", poorQuantity);
        atomMap.put("scrapQuantity", scrapQuantity);
        atomMap.put("unit", unit);
        return atomMap;
    }

    /****************************与数据库交互**********************************/

    //获取报工编号
    private String getReportNumber(String batchNumber, String equipId) {
        List<JSONObject> jsonObjectList = this.logicInstanceDslService.queryWithoutHier("orderNumber = '" + batchNumber + "'", "workReport", null);
        if(CollectionUtil.isNotEmpty(jsonObjectList)){
            return jsonObjectList.get(0).getString("number");
        }
        return null;
    }


    //获取工位
    private String getWorkUnits(String batchNumber) {


        return null;

    }

    /**
     * 获取物料使用记录
     * @param batchNumber 批次号
     * @return
     */
    private  List<JSONObject> getUseMaterialRecords(String batchNumber) {
        List<JSONObject> jsonObjectList = this.logicInstanceDslService.queryWithoutHier("orderNumber = '" + batchNumber + "'", "workReport", null);
        if(CollectionUtil.isNotEmpty(jsonObjectList)){
            JSONObject jsonObject = jsonObjectList.get(0);
            Long id = jsonObjectList.get(0).getLong("id");
            List<JSONObject> insJsonList = this.logicInstanceDslService.queryWithoutHier("form_id = " + id + " and form_type = 10 and stock_type = 2 ", "stockDetail", null);
            return this.transUseMaterialToJsonList(jsonObject,insJsonList);
        }else{
            return new ArrayList<>();
        }
    }


    /**
     * 获取退料记录
     * @param batchNumber 批次号
     * @return
     */
    private  List<JSONObject> getReturnMaterialRecords(String batchNumber) {
        List<JSONObject> jsonObjectList = this.logicInstanceDslService.queryWithoutHier("orderNumber = '" + batchNumber + "'", "materialReturn", null);
        if(CollectionUtil.isNotEmpty(jsonObjectList)){
            JSONObject jsonObject = jsonObjectList.get(0);
            Long id = jsonObjectList.get(0).getLong("id");
            List<HierInstance> hierInstanceList = this.hierInstanceDslService.queryByContainerId("logic", id, "materialReturn", "parentId = '2y1czhlbifw000'");
            return this.transReturnMaterialToJsonList(jsonObject,hierInstanceList);
        }else{
            return new ArrayList<>();
        }
    }

    /**
     * 获取领料记录
     * @param batchNumber 批次号
     * @return
     */
    private  List<JSONObject> getPickMaterialRecords(String batchNumber) {
        List<JSONObject> jsonObjectList = this.logicInstanceDslService.queryWithoutHier("orderNumber = '" + batchNumber + "'", "materialRecord", null);
        if(CollectionUtil.isNotEmpty(jsonObjectList)){
            JSONObject jsonObject = jsonObjectList.get(0);
            Long id = jsonObjectList.get(0).getLong("id");
            List<HierInstance> hierInstanceList = this.hierInstanceDslService.queryByContainerId("logic", id, "materialRecord", "parentId = '870a7a31025d429bbed9dbbe04383890'");
            return this.transPickMaterialToJsonList(jsonObject,hierInstanceList);
        }else{
            return new ArrayList<>();
        }
    }


    /**
     * 获取报工记录
     * @param reportRecordNumber
     * @return
     */
    private  List<JSONObject> getWorReportRecords(String reportRecordNumber) {
        List<JSONObject> jsonObjectList = this.logicInstanceDslService.queryWithoutHier("number = '" + reportRecordNumber + "'", "workReport", null);
        if(CollectionUtil.isNotEmpty(jsonObjectList)){
            JSONObject jsonObject = jsonObjectList.get(0);
            Long id = jsonObjectList.get(0).getLong("id");
            List<HierInstance> hierInstanceList = this.hierInstanceDslService.queryByContainerId("logic", id, "workReport", "parentId = '4ja1eoa9f6o000'");
            return this.transWorkReportToJsonList(jsonObject,hierInstanceList);
        }else{
            return new ArrayList<>();
        }
    }

    /**
     * 获取报工用料记录
     * @param workReportJson 报工单
     * @param insJsonList
     * @return
     */
    private List<JSONObject> transUseMaterialToJsonList(JSONObject workReportJson, List<JSONObject> insJsonList) {
        JSONObject values = workReportJson.getJSONObject("values");
        String className = workReportJson.getString("className");
        String batchNumber = values.getString("orderNumber");
        if (CollectionUtil.isNotEmpty(insJsonList)) {
            List<JSONObject> valueList = insJsonList.stream().map(insJson -> {
                JSONObject jsonValues = insJson.getJSONObject("values");
                JSONObject useValues = new JSONObject();
                jsonValues.put("className", className);
                useValues.put("batchNumber", batchNumber);
                useValues.put("material_id",jsonValues.getString("material_id"));
                useValues.put("material_pcode", jsonValues.getString("material_pcode"));
                useValues.put("material_bcode", jsonValues.getString("material_bcode"));
                useValues.put("material_unit",  jsonValues.getString("material_unit"));
                useValues.put("quantity", jsonValues.getDouble("quantity"));
                useValues.put("uniqueCode",  jsonValues.getDouble("uniqueCode"));
                return useValues;
            }).collect(Collectors.toList());
            return valueList;
        } else {
            return new ArrayList<>();
        }
    }

    /**
     * 将退料明细hierInstanceList转换为json
     * @param hierInstanceList 参数
     * @return 转换结果
     */
    private List<JSONObject> transReturnMaterialToJsonList(JSONObject materialRecordJson, List<HierInstance> hierInstanceList) {
        JSONObject values = materialRecordJson.getJSONObject("values");
        String batchNumber = values.getString("orderNumber");
        if (CollectionUtil.isNotEmpty(hierInstanceList)) {
            List<JSONObject> valueList = hierInstanceList.stream().map(hierInstance -> {
                JSONObject hierValues = hierInstance.getValues();
                JSONObject jsonValues = new JSONObject();
                jsonValues.put("className", hierInstance.getClassName());
                jsonValues.put("batchNumber", batchNumber);
                jsonValues.put("material_id", hierValues.getLong("material_id"));
                jsonValues.put("material_pcode", hierValues.getString("material_pcode"));
                jsonValues.put("material_bcode", hierValues.getString("material_bcode"));
                jsonValues.put("material_unit", hierValues.getString("material_unit"));
                jsonValues.put("quantity", hierValues.getDouble("quantity"));
                jsonValues.put("uniqueCode", hierValues.getString("uniqueCode"));
                return jsonValues;
            }).collect(Collectors.toList());
            return valueList;
        } else {
            return new ArrayList<>();
        }
    }
    /**
     * 将领料明细hierInstanceList转换为json
     * @param hierInstanceList 参数
     * @return 转换结果
     */
    private List<JSONObject> transPickMaterialToJsonList(JSONObject pickMaterialJson, List<HierInstance> hierInstanceList) {
        JSONObject values = pickMaterialJson.getJSONObject("values");
        String batchNumber = values.getString("orderNumber");
        if (CollectionUtil.isNotEmpty(hierInstanceList)) {
            List<JSONObject> valueList = hierInstanceList.stream().map(hierInstance -> {
                JSONObject hierValues = hierInstance.getValues();
                JSONObject jsonValues = new JSONObject();
                jsonValues.put("className", hierInstance.getClassName());
                jsonValues.put("batchNumber", batchNumber);
                jsonValues.put("material_id", hierValues.getLong("material_id"));
                jsonValues.put("material_pcode", hierValues.getString("material_pcode"));
                jsonValues.put("material_bcode", hierValues.getString("material_bcode"));
                jsonValues.put("material_unit", hierValues.getString("material_unit"));
                jsonValues.put("quantity", hierValues.getDouble("quantity"));
                jsonValues.put("uniqueCode", hierValues.getString("uniqueCode"));
                return jsonValues;
            }).collect(Collectors.toList());
            return valueList;
        } else {
            return new ArrayList<>();
        }
    }

    /**
     * 将报工明细hierInstanceList转换为json
     * @param hierInstanceList 参数
     * @return 转换结果
     */
    private List<JSONObject> transWorkReportToJsonList(JSONObject workReportJson, List<HierInstance> hierInstanceList) {
        JSONObject values = workReportJson.getJSONObject("values");
        String equipIds = values.getString("equipIds");
        String equipCodes = values.getString("equipCodes");
        String equipNames = values.getString("equipNames");
        String reportRecordNumber = values.getString("number");
        String batchNumber = values.getString("orderNumber");
        String wppId = values.getString("wppId");
        String wppCode = values.getString("wppCode");
        String wppName = values.getString("wppName");
        Integer lineBodyId = values.getInteger("lineBodyId");
        String lineBody = values.getString("lineBody");
        String lineBodyName = values.getString("lineBodyName");
        if (CollectionUtil.isNotEmpty(hierInstanceList)) {
            List<JSONObject> valueList = hierInstanceList.stream().map(hierInstance -> {
                JSONObject jsonValues = hierInstance.getValues();
                jsonValues.put("id", hierInstance.getId());
                jsonValues.put("className", hierInstance.getClassName());
                jsonValues.put("equipIds", equipIds);
                jsonValues.put("equipCodes", equipCodes);
                jsonValues.put("equipNames", equipNames);
                jsonValues.put("reportRecordNumber", reportRecordNumber);
                jsonValues.put("batchNumber", batchNumber);
                jsonValues.put("wppId", wppId);
                jsonValues.put("wppCode", wppCode);
                jsonValues.put("wppName", wppName);
                jsonValues.put("lineBodyId", lineBodyId);
                jsonValues.put("lineBody", lineBody);
                jsonValues.put("lineBodyName", lineBodyName);
                return jsonValues;
            }).collect(Collectors.toList());
            return valueList;
        } else {
            return new ArrayList<>();
        }
    }

    /**
     *保存批次信息
     * @param batchMapList
     */
    private void addBatchTable(List<Map<String, Object>> batchMapList ) {
    }

    /**
     * 保存产品信息
     * @param productMap
     */
    private void addProduct(Map<String, Object> productMap) {
        product.add(productMap);
    }

    private void addMaterial(Map<String, Object> recordMap) {
        atom.add(recordMap);
    }

    /**
     * 保存原子表
     * @param atomMap
     */
    private void addRecord(Map<String, Object> atomMap) {
        atom.add(atomMap);
    }
}
